<?php
if ($classcoursetype == "classes") {
    $sendval = "classId";
    $thisclasscourse = "class";
} else {
    $sendval = "courseId";
    $thisclasscourse = "course";
}
?> 
<!--//<form class="form" role="form">-->
<div class="row">
    <div class="form-group">
        <input type="hidden" id='classreview_id' value="<?php echo $model->id; ?>">
        <textarea class="form-control review-form"  placeholder="Write your review" style="min-height:166px" name="Reviews['reviews_text']" id="reviews_text" onkeyup ="countChar(this);"></textarea>
        <div class="errorMessage" id="error_reviews_text" style="display:none;">Please Write Your Review.</div>
        <div id="charNum" class="errorMessage"></div></div>                  
    <input type="submit" class="btn review-btn" id="submitLbtR" value="submit">
    <span href="#" class="review-btn" id="review-dismis">cancel</span>
    <div id="reviewLoder" style="display: none"><img  class="reviewloader"src="<?php echo ThemePath(); ?>/images/myskill.gif"></img></div> 
</div>
<!--</form> -->


<script>
    $("#submitLbtR").click(function() {
        var text = $("#reviews_text").val();
        var classId = $("#classreview_id").val();
        if (text == '') {
            $("#error_reviews_text").show();
        } else {
            var result = countChar(reviews_text);
            if (result != false) {
                jQuery.ajax({
                    'type': 'POST',
                    'url': "<?php echo Yii::app()->createAbsoluteUrl("Reviews/create"); ?>",
                    'data': "YII_CSRF_TOKEN=" + $('input[name="YII_CSRF_TOKEN"]').val() + "&<?php echo $sendval; ?>=" + classId + "&text=" + text,
                    'beforeSend': function(jqXHR, settings) {
                        $("#reviewLoder").show();
                    },
                    'success': function(result) {
                        $("#reviewLoder").hide();
                        if ($.trim(result) == 'redirect') {
                            window.location = "#top-position";
                            $('#login-panel').slideToggle();
                            return false;
                        }
                        if ($.trim(result) == 'againsameuser') {
                            $("#reviews_text_success").hide();
                            $("#error_reviews_text").show();
                            $("#error_reviews_text").text("You  have already made a query for this <?php echo $thisclasscourse; ?>.").show();
                            return false;
                        }
                        if ($.trim(result) == 'fail') {
                            $("#error_reviews_text").show();
                            $("#reviews_text_success").hide();
                            $("#error_reviews_text").text("You can't give own review.").show();
                            return false;
                        }

                        if ($.trim(result) != 'againsameuser' && $.trim(result) != 'fail') {
                            $("#reviews-text").val('');
                            $(".add-review").hide();
                            $("#error_reviews_text").hide();
                            $("#reviews_text_success").text(result);
                        }
                    },
                    'cache': false
                });
            }
        }
    })



</script>



